package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo04.do")
public class Demo04Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //请求转发：在多个Servlet之间进行转发
        //转发的对象是：同一个request对象和同一个response对象
        //可以实现请求参数的共享和request域属性的共享
        String username = req.getParameter("username");

        //域属性设置
        //域：像HashMap一样 以键值对存储数据的对象
        //域的 key 都是String;value 都是Object
        //对域 进行属性的赋值
//        req.setAttribute();
        //对域 进行属性的取值
//        req.getAttribute()
        req.setAttribute("name1", "value1");
        req.getRequestDispatcher("/demo05.do").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
